import { requestClient } from '#/api/request';

export namespace OrgApi {
  export interface Org {
    [key: number]: any;
    children?: Org[];
    oid: number;
    ono: string;
    otype: string;
    oname: string;
    pono: string;
    level: number;
    status: 0 | 1;
    memo: string;
    createdTime: string;
    lastUpdateBy: string;
  }
}

/**
 * 获取部门分页列表数据
 */
async function gridOrg() {
  return requestClient.get<Array<OrgApi.Org>>('/system/org/grid');
}
/**
 * 获取部门分页列表数据
 */
async function listOrg() {
  return requestClient.get<Array<OrgApi.Org>>('/system/org/list');
}

/**
 * 创建部门
 * @param data 部门数据
 */
async function createOrg(data: Omit<OrgApi.Org, 'children' | 'oid'>) {
  return requestClient.post('/system/org', data);
}

/**
 * 更新部门
 *
 * @param id 部门 ID
 * @param data 部门数据
 */
async function modifyOrg(data: OrgApi.Org) {
  return requestClient.post(`/system/org/modify`, data);
}
/**
 * 更新部门
 *
 * @param id 部门 ID
 * @param data 部门数据
 */
async function removeOrg(data: OrgApi.Org) {
  return requestClient.post(`/system/org/remove`, data);
}

/**
 * 删除部门
 * @param id 部门 ID
 */
async function deleteOrg(id: number) {
  return requestClient.delete(`/system/org/${id}`);
}

export { createOrg, deleteOrg, gridOrg, listOrg, modifyOrg, removeOrg };
